package com.example.wwk.graduationpractice.Globalutils;

import android.app.Application;
import android.content.Context;


import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.packet.Presence;
import org.litepal.LitePalApplication;


/**
 * Created by wwk on 2017/3/8.
 * 获取全局的context
 * 获取全局的smack connection
 */

public class MyApplication extends Application  {
    private static Context context;
    private static AbstractXMPPConnection connection;
    @Override
    public void onCreate() {
        LitePalApplication.initialize(this);//litepal Appilcation 初始化
        context = getApplicationContext();

    }
    public static Context getContext(){
        return context;
    }
    public static void  setConnection(AbstractXMPPConnection con){
        connection = con;
    }
    public static void  disConnection(){
        Presence presence = new Presence(Presence.Type.unavailable);
        try {
            connection.disconnect(presence);
            connection =null;
        } catch (SmackException.NotConnectedException e) {
            e.printStackTrace();
        }

    }
    public static AbstractXMPPConnection getConnection(){
        return connection;
    }
}
